package com.dayu.finecomm.iot;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;

/**
 * IotDriverAdapter, 协议处理适配器
 * @author XuJialiang
 * @since 2017-09-09 10:22:12
 * @version V1.0.0
 */
public class IotDriverAdapter {
	/**
	 * 处理IOT消息的device
	 */
	private ChannelInitializer<?> mChannel = null;
	
	IotDriverAdapter(ChannelInitializer<?> channel) {
		mChannel = channel;
	}
	/**
	 * 发送用户数据给APP应用
	 * @param socket DTU remote address
	 * @param msg
	 */
	public void initChannel(ChannelHandlerContext ctx) {
		if (null != mChannel) {
			try {
				ctx.pipeline().addLast(mChannel);
				mChannel.channelRegistered(ctx);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 获取ChannelInitializer
	 * @return
	 */
	public ChannelInitializer<?> getChannelHandler() {
		return mChannel;
	}
}
